﻿#ifndef ACCOUNTINFORMATION_H
#define ACCOUNTINFORMATION_H

#include <QFont>
#include <QDBusInterface>
#include <QDBusReply>
#include <QGSettings>
#include <QObject>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDebug>
#include <QDir>
#include <QSettings>
#include <QProcess>
#include <QTranslator>
#include <QApplication>
#include <QPainter>
#include "../dbusmanager.h"

#define DEFAULTFACECOMMUNITY "/usr/share/ukui/faces/01-default-community.png"
#define DEFAULTFACECOMMERCIAL "/usr/share/ukui/faces/01-default-commercial.png"
#define DEFAULTFACE (AccountInformation::isCommunity())?DEFAULTFACECOMMUNITY:DEFAULTFACECOMMERCIAL


#define KYLIN_POWER_NORMAL_NAME           "pad_mainpower"

#define KYLIN_POWER_NORMAL_PATH_INTEL     ":/image/pad_mainpower.png"
#define KYLIN_POWER_NORMAL_PATH_MAJOR     ":/image_major/icon-shutdown.svg"

#define ADMINISTRATORS 1
#define STANDARDUSER   0

/* qt会将glib里的signals成员识别为宏，所以取消该宏
 * 后面如果用到signals时，使用Q_SIGNALS代替即可
 **/
#ifdef signals
#undef signals
#endif

extern "C" {
#include <glib.h>
#include <gio/gio.h>
}

typedef struct _UserInfomation {
    QString objpath;
    QString username;
    QString realname;
    QString iconfile;
    QString passwd;
    int accounttype;
    int passwdtype;
    bool current;
    bool logined;
    bool autologin;
    bool noPwdLogin;
    qint64 uid;
}UserInfomation;

class IconLabel;

class AccountInformation : public QWidget
{
    Q_OBJECT
public:
    explicit AccountInformation(QWidget *parent = nullptr);

private:
    void initMemberVariable();
    void initLayout();
    void registeredAccountsDbus();
    void setAllControlsLabelInfo();
    bool isCommunity();

    QStringList getUserObjectPath();
    UserInfomation GetUserInformation(QString objpath);
    QPixmap PixmapToRound(const QPixmap &src, int radius);
    QPixmap pixmapAdjustLabel(QString iconfile);

private:
    IconLabel    *m_pHeadPortraitIconLabel;
    QLabel       *m_pNameLabel;
    QLabel       *m_pIdentityLabel;
    QHBoxLayout  *m_pMainLayout;
    QVBoxLayout  *m_pVLabelLayout;
    QWidget      *m_pInfoWidget;
    QDBusInterface * m_pSystemUserIface;
    QGSettings   *m_gsettings;
    QString      adminIstrators;
    QString      standardUser;


private slots:
    void openContorlCenterWidgetSlots();
    void AccountSlots(QString property, QMap<QString, QVariant> propertyMap, QStringList propertyList);

Q_SIGNALS:

};

class ShutDownWidget : public QWidget
{
    Q_OBJECT
public:
    explicit ShutDownWidget(QWidget *parent = nullptr);

private:
    void initLayout();

private:
    QPushButton  *m_pShutDownButton;
    QHBoxLayout  *m_pMainLayout;
    QGSettings   *m_gsettings;

private slots:
    void openShutdownWidgetSlots();

Q_SIGNALS:

};

class IconLabel : public QLabel
{
    Q_OBJECT
public:
    explicit IconLabel(QWidget *parent = nullptr);

protected:
    virtual void mouseReleaseEvent(QMouseEvent *ev);

Q_SIGNALS:
    void LabelClicked();

};

#endif // ACCOUNTINFORMATION_H
